﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

using Bussiness_Objects;

namespace WindowsFormsApplication1
{
    public partial class TuyChinh : Form
    {
        public TuyChinh()
        {
            InitializeComponent();
        }

        protected override void OnShown(EventArgs e)
        {
            setValue();
            base.OnShown(e);
        }

        private void setValue()
        {
            txtTuoi_ToiThieu.Text = MainForm._ThamSo.tuoiToiThieu.ToString();
            txtTuoi_ToiDa.Text = MainForm._ThamSo.tuoiToiDa.ToString();
            txtThoiHanThe.Text = MainForm._ThamSo.thoiHanThe.ToString();
            txtNamXB.Text = MainForm._ThamSo.khoangCachNamXB.ToString();
            txtNgayMuon.Text = MainForm._ThamSo.soNgayMuon.ToString();
            txtSachMuon.Text = MainForm._ThamSo.soSachMuon.ToString();
            txtTienPhat.Text = MainForm._ThamSo.tienPhat.ToString();
            if (MainForm._ThamSo.apDungQD6 == 1)
                switch_but_ThuThien.Value = true;
            else
                switch_but_ThuThien.Value = false;
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void butOK_Click(object sender, EventArgs e)
        {
            UpdateValue();
            MainForm._ThamSo.UpdateValue();
        }

        private void UpdateValue()
        {
            MainForm._ThamSo.Update(txtTuoi_ToiThieu.Tag.ToString(), int.Parse(txtTuoi_ToiThieu.Text));
            MainForm._ThamSo.Update(txtTuoi_ToiDa.Tag.ToString(), int.Parse(txtTuoi_ToiDa.Text));
            MainForm._ThamSo.Update(txtThoiHanThe.Tag.ToString(), int.Parse(txtThoiHanThe.Text));
            MainForm._ThamSo.Update(txtNamXB.Tag.ToString(), int.Parse(txtNamXB.Text));
            MainForm._ThamSo.Update(txtNgayMuon.Tag.ToString(), int.Parse(txtNgayMuon.Text));
            MainForm._ThamSo.Update(txtSachMuon.ToString(), int.Parse(txtSachMuon.Text));
            MainForm._ThamSo.Update(txtTienPhat.Tag.ToString(), int.Parse(txtTienPhat.Text));
            int value;
            if (switch_but_ThuThien.Value == true)
                value = 1;
            else
                value = 0;
            MainForm._ThamSo.Update(switch_but_ThuThien.Tag.ToString(), value);
        }
    }
}
